#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
queue<int> q;
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int m, y;
		cin >> m;
		if (m == 1)
		{
			cin >> y;
			q.push(y);
		}
		else if (m == 2)
		{
			if (q.empty())
			{
				cout << "ERR_CANNOT_POP"<<endl;
			}
			else
				q.pop();
		}
		else if (m == 3)
		{
			if (q.empty())
			{
				cout << "ERR_CANNOT_QUERY"<<endl;
			}
			else
				cout << q.front() << endl;
		}
		else
			cout << q.size() << endl;
	}
	return 0;
}